package ruixinyi.experiment2.demos.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ruixinyi.experiment2.demos.web.dao.Sys_roleDao;
import ruixinyi.experiment2.demos.web.entity.Sys_role;

import java.util.List;

@RestController
@RequestMapping("/api/sys_role")
public class Sys_roleController {

    @Autowired
    private Sys_roleDao sys_roleDao;

    // 添加角色信息
    @PostMapping("/add")
    public ResponseEntity<Sys_role> addSysRole(@RequestBody Sys_role sys_role) {
        Sys_role result = sys_roleDao.addSys_role(sys_role);
        return ResponseEntity.ok(result);
    }

    // 获取所有角色信息
    @GetMapping("/all")
    public ResponseEntity<List<Sys_role>> getAllSysRoles() {
        List<Sys_role> sysRoles = sys_roleDao.getAllSys_role();
        return ResponseEntity.ok(sysRoles);
    }

    // 根据ID查询角色信息
    @GetMapping("/{id}")
    public ResponseEntity<Sys_role> getSysRoleById(@PathVariable Integer id) {
        Sys_role sysRole = sys_roleDao.getSys_roleByid(id);
        return ResponseEntity.ok(sysRole);
    }

    // 修改角色信息
    @PutMapping("/update")
    public ResponseEntity<Integer> updateSysRole(@RequestBody Sys_role sys_role) {
        int result = sys_roleDao.updateSys_role(sys_role);
        return ResponseEntity.ok(result);
    }

    // 根据ID删除角色信息
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Integer> deleteSysRoleById(@PathVariable Integer id) {
        int result = sys_roleDao.deleteSys_roleByid(id);
        return ResponseEntity.ok(result);
    }
}